<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>{$user.id} - 读者</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="/static/layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="/static/layuiadmin/style/admin.css" media="all">
  <style>
    table .layui-form-radio > i {
      font-size: 16px !important;
    }
  </style>
</head>
<body>
  
  <div class="layui-fluid">
    <div class="layui-row layui-col-space15">

      <div class="layui-col-md4">
        <div class="layui-card">
          <div class="layui-card-header">读者信息</div>
          <div class="layui-card-body layui-text">
            <table class="layui-table">
              <colgroup>
                <col width="150">
                <col>
              </colgroup>
              <tbody>
              <tr>
                <td>用户ID</td>
                <td>
                  {$user.id}
                </td>
              </tr>
              <tr>
                <td>用户昵称</td>
                <td>
                  {$user.nickname}
                </td>
              </tr>
              <tr>
                <td>App</td>
                <td>
                  {$user.quick_app.name}
                </td>
              </tr>
              <tr>
                <td>手机厂商</td>
                <td>
                  {$user.provider}
                </td>
              </tr>
              <tr>
                <td>读者身份</td>
                <td class="vip_text">
                  {if $user.vip_text == 'vip会员'}
                  <span style="color: #009688;">vip会员</span>
                  {else /}
                  普通会员
                  {/if}
                </td>
              </tr>

              {if $role->alias != 'channel' && $role->alias != 'agent'}
              <tr>
                <td>归属代理</td>
                <td>
                  {if $user.agent}
                  {$user.agent.account}
                  {elseif $user.agent_id > 0 /}
                  <span style="color:#c00; ">投放号信息异常</span>
                  {else /}
                  {/if}
                </td>
              </tr>
              <tr>
                <td>归属投放号</td>
                <td>
                  {if $user.channel}
                  {$user.channel.account}
                  {elseif $user.channel_id > 0 /}
                  <span style="color:#c00; ">投放号信息异常</span>
                  {else /}
                  {/if}
                </td>
              </tr>
              <tr>
                <td>来源代理</td>
                <td>
                  {if $user.source_agent}
                  {$user.source_agent.account}
                  {elseif $user.source_agent_id > 0 /}
                  <span style="color:#c00; ">来源投放号信息异常</span>
                  {else /}
                  {/if}
                </td>
              </tr>
              <tr>
                <td>来源投放号</td>
                <td>
                  {if $user.source_channel}
                  {$user.source_channel.account}
                  {elseif $user.source_channel_id > 0 /}
                  <span style="color:#c00; ">来源投放号信息异常</span>
                  {else /}
                  {/if}
                </td>
              </tr>
              <tr>
                <td lay-tips="加人白名单，用户直接展示隐藏数据（屏蔽地区也失效），权重最高（绝对拉黑例外）">白名单</td>
                <td>
                  <div class="layui-form">
                    <input type="radio" name="white" lay-filter="white"  value="1" title="加入" {if $user.white}checked{/if}>
                    <input type="radio" name="white" lay-filter="white"  value="2" title="未加入" {if !$user.white}checked{/if}>
                  </div>
                </td>
              </tr>
              <tr>
                <td lay-tips="加人黑名单，用户只能看见审核内容，绝对拉黑后读者进入不了App">黑名单</td>
                <td>
                  <div class="layui-form">
                    <input type="radio"  name="black" lay-filter="black"  value="0" title="正常用户"   {if !$user.black || $user.black['status'] == 0}checked{/if}>
                    <input type="radio"  name="black"  lay-filter="black"  value="1"  title="黑名单"   {if $user.black && $user.black['status'] == 1}checked{/if}>
                  </div>
                </td>
              </tr>
              <tr>
                <td lay-tips="疑似审核人员，在审核期间访问审核版本App的读者，只能看见审核内容，可在审核事件页面忽略">疑似审核人</td>
                <td>
                  {if $user.auditor}<span style="color: #FF5722;">是</span>{else /}否{/if}
                </td>
              </tr>
              {/if}
              <tr>
                <td>手机号码</td>
                <td>
                  {$user.phone}
                </td>
              </tr>
              <tr>
                <td>注册时间</td>
                <td>
                  {$user.regtime}
                </td>
              </tr>
              <tr>
                <td>注册IP</td>
                <td>
                  {$user.ip_addr}
                </td>
              </tr>
              </tbody>
            </table>
          </div>
        </div>
        <div class="layui-card">
          <div class="layui-card-header">
            额外信息
          </div>
          <div class="layui-card-body layui-text layadmin-text" style="word-break:break-all;">
            token：<br>
            {$user.token}<br>
            <hr>
            设备唯一标识：<br>
            {$user.device_id}<br>
            {if $role->alias == 'admin'}
            <br>
            <button type="button" class="layui-btn layui-btn-sm" onclick="refreshUser();">用户刷新</button>
            {/if}
            <hr>
            读者UA：<br>
            {$user.ua.ua}
          </div>
        </div>
      </div>

      <div class="layui-col-md8">
        <div class="layui-row layui-col-space15">
          <div class="layui-col-md12">
            <div class="layui-card">

              {if $role->alias == 'admin' || $role->alias == 'service'}
              <div class="layui-card-header">账户信息<button style="margin-left: 15px;" class="layui-btn layui-btn-sm" id="recharge_btn" data-uid="{$user.id}">充值</button></div>
              {else /}
              <div class="layui-card-header">账户信息</div>
              {/if}



              <div class="layui-card-body">

                <div class="layui-carousel layadmin-carousel layadmin-backlog">
                  <div carousel-item>
                    <ul class="layui-row layui-col-space10">
                      <li class="layui-col-xs6">
                        <a class="layadmin-backlog-body">
                          <h3>书币余额</h3>
                          <p><cite class="book_coin">{$user.book_coin}</cite></p>
                        </a>
                      </li>
                      <li class="layui-col-xs6">
                        <a class="layadmin-backlog-body">
                          <h3>书点余额</h3>
                          <p><cite>{$bp}</cite></p>
                        </a>
                      </li>
                      <li class="layui-col-xs6">
                        <a class="layadmin-backlog-body">
                          <h3>累计消耗书币</h3>
                          <p><cite>{if $consume}{$consume.used_coin}{else /}0{/if}</cite></p>
                        </a>
                      </li>
                      <li class="layui-col-xs6">
                        <a  class="layadmin-backlog-body">
                          <h3>累计消耗书点</h3>
                          <p><cite>{if $consume}{$consume.used_point}{else /}0{/if}</cite></p>
                        </a>
                      </li>
                    </ul>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div class="layui-col-md12">
            <div class="layui-card">
              <div class="layui-tab layui-tab-brief layadmin-latestData">
                <ul class="layui-tab-title">
                  <li class="layui-this">阅读记录</li>
                  <li>领取记录</li>
                  <li>充值记录</li>
                  <li>读者书架</li>
                </ul>
                <div class="layui-tab-content">
                  <div class="layui-tab-item layui-show">
                    <div class="layui-form layuiadmin-card-header-auto">

                      <div class="layui-form-item">

                        <div class="layui-inline">
                            <input type="text" name="month" class="layui-input" id="month" placeholder="检索月份" value="{$month}" readonly>
                        </div>

                        <div class="layui-inline">
                          <select name="pay_read" >
                            <option value="">是否付费</option>
                            <option value="1">付费阅读</option>
                            <option value="0">免费阅读</option>
                          </select>
                        </div>

                        <div class="layui-inline">
                          <input type="text" name="novel_id" placeholder="小说ID" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline">
                          <input type="text" name="chapter_no" placeholder="章节序号" autocomplete="off" class="layui-input">
                        </div>

                        <div class="layui-inline">
                          <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-user-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                          </button>
                        </div>

                      </div>

                    </div>

                    <table id="LAY-index-topSearch"></table>
                  </div>
                  <div class="layui-tab-item">
                    <div class="layui-form layuiadmin-card-header-auto">
                      <div class="layui-form-item">
                        <div class="layui-inline">
                          <select name="give_type" >
                            <option value="">赠送类型</option>
                            <option value="1">充值赠送</option>
                            <option value="2">后台充值</option>
                            <option value="3">加桌赠送</option>
                            <option value="4">签到赠送</option>
                            <option value="5">绑定号码</option>
                          </select>
                        </div>
                        <div class="layui-inline">
                          <select name="is_overdue">
                            <option value="">是否过期</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                          </select>
                        </div>
                        <div class="layui-inline">
                          <select name="is_expire">
                            <option value="">是否失效</option>
                            <option value="1">是</option>
                            <option value="0">否</option>
                          </select>
                        </div>
                        <div class="layui-inline">
                          <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="LAY-give-back-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                          </button>
                        </div>

                      </div>

                    </div>

                    <table id="LAY-index-topCard"></table>
                    <script type="text/html" id="typeTpl">
                      {{#  if(d.give_type == 1){ }}
                      <span style="color: #5FB878;">支付购买</span>
                      {{#  } else if(d.give_type == 2) { }}
                      <span style="color: #5FB878;">后台充值</span>
                      {{#  } else if(d.give_type == 3) { }}
                      <span style="color: #5FB878;">加桌赠送</span>
                      {{#  } else if(d.give_type == 4) { }}
                      <span style="color: #5FB878;">签到赠送</span>
                      {{#  } else if(d.give_type == 5) { }}
                      <span style="color: #5FB878;">绑定号码</span>
                      {{#  } else if(d.give_type == 6) { }}
                      <span style="color: #5FB878;">日历提醒</span>
                      {{#  } else if(d.give_type == 7) { }}
                      <span style="color: #5FB878;">阅读X章节</span>
                      {{#  } else if(d.give_type == 8) { }}
                      <span style="color: #5FB878;">充值赠送</span>
                      {{#  } else { }}
                      <span>类型未知</span>
                      {{#  } }}
                    </script>
                  </div>
                  <div class="layui-tab-item">
                    <div class="layui-form layuiadmin-card-header-auto">
                    </div>
                    <table id="LAY-index-pay"></table>
                  </div>
                  <div class="layui-tab-item">
                    <div class="layui-form layuiadmin-card-header-auto">
                    </div>
                    <table id="LAY-index-shujia"></table>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>

    </div>
  </div>

  <script src="/static/layuiadmin/layui/layui.js?t=1"></script>  
  <script>
  layui.config({
    base: '/static/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'form', 'console'], function () {
    var form = layui.form
            ,admin = layui.admin
            ,$ = layui.$
            ,table = layui.table
            ,laydate = layui.laydate;

    $('#recharge_btn').click(function () {
      var uid = $(this).attr('data-uid');

      layer.open({
        type: 2
        ,title: '用户充值'
        ,content: "{:url('User/recharge')}?id="+uid
        ,maxmin: true
        ,area: ['460px', '320px']
        ,btn: ['确定', '取消']
        ,btnAlign: 'c'
        ,yes: function(index, layero){

          var iframeWindow = window['layui-layer-iframe'+ index]
                  ,submitID = 'LAY-data-recharge-submit'
                  ,submit = layero.find('iframe').contents().find('#'+ submitID);

          //监听提交
          iframeWindow.layui.form.on('submit('+ submitID +')', function(data){

            $.ajax({
              url:"{:url('User/recharge')}?id="+uid,
              type:"post",
              dataType: "json",
              data:data.field,
              async:true,
              success: function(rs){
                if(rs['code'] == 100){

                  layer.msg(rs['msg'],function () {
                    if(rs['data']['type'] == 1)
                    {
                      $('.book_coin').html(rs['data']['book_coin']);
                    }else{
                      $('.vip_text').html(rs['data']['vip_text']);
                    }
                    layer.close(index); //关闭弹层

                  });

                }else{
                  layer.msg(rs['msg']);
                }
                return false;
              }
            });
          });

          submit.trigger('click');
        }
      });

    })

    form.on('radio(review)', function (data) {
      layer.confirm('确认切换状态，请谨慎操作！', {closeBtn:0,title:false,icon:7},function(index){
        admin.req({
          url: "/user/changeReviewType"
          , type: "POST"
          , data: {'uid': '{$user.id}', 'type': data.value}
          , done: function (res) {
            layer.msg('设置成功', {offset: '15px', icon: 1, time: 1000});
          }, not_finish: function (res) {
            layer.msg(res.msg,function () {
            });
          }
        });
      },function () {
        if (data.value == 2){
          $("input[type='radio'][name='review'][value='1']").prop("checked", true);
          $("input[type='radio'][name='review'][value='2']").prop("checked", false);
        }
        if (data.value == 1){
          $("input[type='radio'][name='review'][value='1']").prop("checked", false);
          $("input[type='radio'][name='review'][value='2']").prop("checked", true);
        }
        form.render();
      });
    });


    form.on('radio(white)', function (data) {
      admin.req({
        url: "/user/cutBlackOrWhite"
        , type: "POST"
        , data: {'uid': '{$user.id}', 'type': data.value, 'table_suffix': 'white'}
        , done: function (res) {
          layer.msg('设置成功', {offset: '15px', icon: 1, time: 1000});
        }, not_finish: function (res) {
          layer.msg(res.msg, function () {
          });
        }
      });
    });

    form.on('radio(black)', function (data) {
      admin.req({
        url: "/user/cutBlackOrWhite"
        , type: "POST"
        , data: {'uid': '{$user.id}', 'type': data.value, 'table_suffix': 'black'}
        , done: function (res) {
          layer.msg('设置成功', {offset: '15px', icon: 1, time: 1000});
        }, not_finish: function (res) {
          layer.msg(res.msg, function () {
          });
        }
      });
    });


    //年月选择器

    var date = new Date();
    date.setMonth(date.getMonth() + 1);
    date.setDate(0);
    var lastDay = date.toLocaleDateString();
    laydate.render({
      elem: '#month'
      ,min: '2023-07-01'
      ,max: lastDay
      ,type: 'month'
      ,format: 'yyyyMM'
    });

    //读者书架
    table.render({
      elem: '#LAY-index-shujia'
      ,url: '/user/bookshelf?uid={$user.id}'
      ,page: true
      , response: {
        statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
      }
      ,cellMinWidth: 120
      ,cols: [[
        {field: 'id',title: '书架id',width:80}
        ,{field: 'novel', title: '小说',minWidth:200, templet:function (d) {
            if (d.novel){
              return "["+d.novel.id+"] "+d.novel.title;
            }else {
              return '<span style="color:#FF5722">小说不存在</span>';
            }
          }}
        , {
          field: 'status', title: '状态', templet: function (d) {
            if (d.delete_time === 0) {
              return '<span style="color:#5FB878">无</span>';
            } else {
              return '<span style="color:#FF5722">用户删除</span>';
            }
          }, align:'center'
        }
        ,{field: 'read_time', title: '最近阅读时间'}
        ,{field: 'create_time', title: '创建时间',minWidth:170}
      ]]
      ,skin: 'line'
    });

    //阅读记录
    table.render({
      elem: '#LAY-index-topSearch'
      ,url: '/user/readRecordDetail?uid={$user.id}'
      , response: {
        statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
      }
      ,page: true
      , limits: [15, 30, 40, 50, 100]
      , limit: 15
      ,cols: [[
        {type: 'numbers', fixed: 'left'}
        ,{field: 'novel_id', title: '书籍', minWidth: 300, templet: function (d) {
            return "[" + d.novel_id + "] " + d.novel_title;
          }}
        ,{field: 'chapter_no', title: '章节', minWidth: 120,templet:function (d) {
            return d.chapter_title;
          }}
        ,{field: 'used_coin', title: '消耗书币'}
        ,{field: 'used_point', title: '消耗书点'}
        ,{field: 'read_time', title: '阅读时间'}
      ]]
      ,skin: 'line'
    });

    form.on('submit(LAY-user-back-search)', function(data){
      var field = data.field;
      if (!field.month){
        layer.msg('选择月份后检索', function () {
        });
        return false;
      }
      //执行重载
      table.reload('LAY-index-topSearch', {
        where: field
        ,page: {
          curr: 1  // 将页码重置为第一页
        }
      });
    });


    let timestamp = Math.floor(Date.now() / 1000);
    //领取记录
    table.render({
      elem: '#LAY-index-topCard'
      ,url: '/user/receiveRecord?uid={$user.id}'
      , response: {
        statusCode: 1 //规定成功的状态码，本来是：0，现在统一改为1
      }
      ,page: true
      ,cellMinWidth: 120
      ,cols: [[
        {type: 'numbers', fixed: 'left'}
        ,{field: 'create_time', title: '领取时间',minWidth:170}
        ,{field: 'give_type', title: '赠送类型',templet:'#typeTpl'}
        ,{field: 'book_point', title: '书点余额'}
        , {
          field: '赠送书点', title: '赠送数量', templet: function (d) {
            return d.book_point + d.used_point;
          }
        }
        , {field: 'overdue_date', title: '过期时间',minWidth:170}
        , {field: 'is_overdue', title: '是否过期',templet:function (d) {
              if (d.overdue_time < timestamp){
                  return '<span style="color: #FF5722">是</span>';
              }else {
                return '否';
              }
          }}
        , {field: 'is_expire', title: '是否失效',templet:function (d) {
            if (d.is_expire == 1){
              return '<span style="color: #FF5722">是</span>';
            }else {
              return '否';
            }
          }}
      ]]
      ,skin: 'line'
    });

    //充值记录
    table.render({
      elem: '#LAY-index-pay'
      ,url: '/order/list_data?uid={$user.id}'
      ,page: true
      ,cellMinWidth: 120
      ,cols: [[
        {field: 'id',title: '订单id',width:80}
        ,{field: 'out_trade_no', title: '订单号', minWidth:200}
        ,{field: 'total_fee', title: '充值金额'}
        , {
          field: 'status', title: '订单状态', templet: function (d) {
            if (d.status == 2) {
              return '<span style="color: #FF5722">已支付</span>';
            } else {
              return '待支付';
            }
          }
        }
        ,{field: 'create_time', title: '下单时间',minWidth:170}
      ]]
      ,skin: 'line'
    });


    form.on('submit(LAY-give-back-search)', function(data){
      var field = data.field;
      //执行重载
      table.reload('LAY-index-topCard', {
        where: field
        ,page: {
          curr: 1  // 将页码重置为第一页
        }
      });
    });

  });
  </script>

  <script>
    function refreshUser() {
      layer.confirm('刷新后清除App缓存，然后重新从链接进入，将会生成新用户！不可恢复请谨慎操作，确认操作吗？', {icon: 0, title: '用户刷新'}, function (index) {
        layui.admin.req({
          url: '/user/refreshUser'
          , type: "POST"
          , data: {'uid': '{$user.id}'}
          , done: function (res) {
            layer.msg('刷新成功', {icon: 1, time: 1000}, function () {
              layer.close(index);
            });
          }, not_finish: function (res) {
            layer.msg(res.msg);
          }
        });
      });
    }
  </script>
</body>
</html>

